package cn.wolfcode.rbac.domain;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.Collection;
import java.util.List;

/**
 * 改造之后的登录主体类
 * 改造前：EmpLoyee
 * 使用spring security 必须遵守spring security 用户体系操作规则--- UserDetails体系---UserDetailsService操作用户对象服务层
 *
 * 思考：怎么让自定义的类融入到spring security 体系中呢？
 * 方案1：实现UserDetails 接口，重写7个方法
 * 方案2： 继承User类，重写构造器， 根据业务改造登录实体
 *
 * 改造后：LLoginUser里面包含当前登录Employee对象
 */
@Getter
@Setter
@ToString
public class LoginUser extends User {
    private Employee employee;
    public LoginUser(String username, String password, Collection<? extends GrantedAuthority> authorities) {
        super(username, password, authorities);
    }

    // 有账号，有密码，有权限
    public LoginUser(Employee employee, Collection<? extends GrantedAuthority> authorities) {
        super(employee.getName(), employee.getPassword(), authorities);
        this.employee = employee;
    }

    // 有账号，有密码，无权限
    public LoginUser(Employee employee) {
        super(employee.getName(), employee.getPassword(), List.of());
        this.employee = employee;
    }
}
